package com.nilhcem.fakesmtp.eventbus;

import com.google.common.eventbus.AsyncEventBus;

import java.util.concurrent.Executors;

public class EventBusContext {

    private AsyncEventBus eventBus;

    private EventBusContext() {
        eventBus = new AsyncEventBus(Executors.newFixedThreadPool(10), new SubscriberExceptionHandlerImpl());
        eventBus.register(new SaveFileSubscribe());
        eventBus.register(new ResendMailSubscribe());
    }

    public static class EventBusContextHolder {
        private static final EventBusContext INSTANCE = new EventBusContext();
    }

    public static EventBusContext getInstance() {
        return EventBusContextHolder.INSTANCE;
    }

    public void postEvent(Object event) {
        this.eventBus.post(event);
    }

}
